package pingpong;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * @author Morten Bormeth
 */
public class Main extends JFrame {
private static final long serialVersionUID = 1L;
    private JPanel jContentPane = null;
    private PanelBall panel = null;
    int windowMaxSize = 400;
    int windowMinSize = 400;

    private PanelBall getPanel() {
        if (panel == null) {
            panel = new PanelBall();
        }
        return panel;
    }

    public Main() {
        super();
        initialize();
        // Keyboard Listeners
        this.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent evt) {
                formKeyPressed(evt);
            }

            @Override
            public void keyReleased(KeyEvent evt) {
                formKeyReleased(evt);
            }
        });

    }

    private void formKeyPressed(KeyEvent evt) {
        panel.keyPressed(evt);
    }

    private void formKeyReleased(KeyEvent evt) {
        panel.keyReleased(evt);
    }

    private void initialize() {
        this.setResizable(false);
        this.setBounds(new Rectangle(312, 184, windowMinSize, windowMaxSize));
        this.setMinimumSize(new Dimension(windowMinSize, windowMinSize));
        this.setMaximumSize(new Dimension(windowMaxSize, windowMaxSize));
        this.setContentPane(getJContentPane());
        this.setTitle("Ping Pong");
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getPanel(), BorderLayout.CENTER);
            jContentPane.setBackground(Color.BLACK);
        }
        return jContentPane;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                Main thisClass = new Main();
                thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                thisClass.setVisible(true);
            }
        });
        
        MP3 mp3 = new MP3("Nordam164.mp3");
        mp3.play();
    }
}